package cqrtplm.controller;

import com.github.pagehelper.PageInfo;
import com.hustcad.plm.pdm.common.model.vo.search.ResultEntityVO;
import com.hustcad.plm.pdm.iteration.dto.TyplmCommonHistoryDTO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.UserQueryDTO;
import cqrtplm.service.QueryPartService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(RouteConstant.PART + "v1")
public class QueryPartController {

    @Resource
    private QueryPartService queryPartService;

    /**
     * 根据类型分页查询数据
     * @param queryPartIFDTO
     * @return
     */
    @PostMapping("/queryPartData")
    public ResponseResult queryPartData(@RequestBody UserQueryDTO queryPartIFDTO){
        return ResponseResult.success(queryPartService.queryPartData(queryPartIFDTO, Boolean.TRUE, Boolean.TRUE));
    }

    /**
     * 根据类型返回IBA
     * @param type
     * @return
     */
    @GetMapping("/getIbaByTypeName")
    public ResponseResult getIbaByTypeName(@RequestBody String type){
        return ResponseResult.success(queryPartService.getIbaByTypeName(type));
    }

    /**
     * 查询数据
     * @param queryPartIFDTO
     * @return
     */
    @PostMapping("/queryPartAndIbaByType")
    public ResponseResult queryPartAndIbaByType(@RequestBody UserQueryDTO queryPartIFDTO){
        return ResponseResult.success(queryPartService.queryPartAndIbaByType(queryPartIFDTO));
    }

    /**
     * 物料变更履历查询
     * @param identifierEntity
     * @return
     */
    @PostMapping("/getVersionHistory")
    public ResponseResult<List<ResultEntityVO>> getVersionHistory(@RequestBody IdentifierEntity identifierEntity) {
        return ResponseResult.success(queryPartService.getVersionHistory(identifierEntity));
    }

    /**
     * 导出查询结果
     * @param queryPartIFDTO
     * @param response
     * @return
     */
    @PostMapping("/exportPartDataFile")
    public void exportPartDataFile(@RequestBody UserQueryDTO queryPartIFDTO, HttpServletResponse response) {
        queryPartService.exportPartDataFile(queryPartIFDTO, response);
    }

}
